package com.example.lvsuo.controller.cxg;

import com.example.lvsuo.entity.cxg.FlowName;
import com.example.lvsuo.entity.cxg.vo.FlowNameVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.cxg.IFlowNameService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *
 * 流程 flow_name
 */

@RestController
@RequestMapping("flownames")
public class FlowNameController {

    @Autowired
    IFlowNameService iFlowNameService;


    /**
     * 查询流程名称
     * @return
     */
    @GetMapping
    public Result getFlowName(FlowNameVo flowNameVo){

        PageHelper.startPage(flowNameVo.getPageCur(),flowNameVo.getPageSize());
        PageInfo pageInfo = new PageInfo(iFlowNameService.getFlowName(flowNameVo));

//        List<FlowName> flowNames = iFlowNameService.getFlowName(flowName.getFname());
        return Result.back("ok","20000",pageInfo);
    }


    /**
     * 添加流程 name
     * @return
     */
    @PostMapping
    public Result addFlownames(@RequestBody FlowName flowName){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd ");//设置日期格式 时间“HH:mm:ss”
        flowName.setCreateDate(df.format(new Date()));// new Date()为获取当前系统时间
        String LastId = iFlowNameService.addFlownames(flowName);// 返回添加的主键
        return Result.back("ok","20000",LastId);
    }

    /**
     * 删除flow_name
     * @param fid
     * @return
     */
    @DeleteMapping
    public Result delFlowName(String fid){
        iFlowNameService.delFlowName(fid);
        return Result.back("ok",20000);
}

    /**
     * 按id查
     * @param id
     * @return
     */
    @GetMapping("/{id}")
public Result getFlowNameByid(@PathVariable String id){
        FlowName flowName = iFlowNameService.getFlowNameByid(id);

        return Result.back("ok","20000",flowName);
}

}
